package com.project.UI;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.mybaseproject.R;
import com.project.UI.news.NewsListFragment;
import com.project.UI.news.NewsViewPagerAdapter;
import com.project.baseApp.BaseFragment;
import com.project.baseApp.Constant;

public class MainContentFragment extends BaseFragment {
	private View v;
	private ViewPager viewPager;
	private String type;
	private NewsViewPagerAdapter adapter;
	private ArrayList<Fragment> fragArray;

	public static MainContentFragment newInstance(String type) {
		MainContentFragment fragment = new MainContentFragment();
		Bundle bundle = new Bundle();
		bundle.putString("type", type);
		fragment.setArguments(bundle);
		return fragment;
	}

	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		this.type = getArguments().getString("type");
		fragArray = new ArrayList<Fragment>();
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		v = inflater.inflate(R.layout.fragment_main_content, container, false);
		return v;
	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		viewPager = (ViewPager) view.findViewById(R.id.base_view_pager);

		super.onViewCreated(view, savedInstanceState);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		if (type.equals("news")) {
			fragArray.add(NewsListFragment.newInstance(0));
			fragArray.add(NewsListFragment.newInstance(1));
			fragArray.add(NewsListFragment.newInstance(2));
		} else if (type.equals("show")) {

		}
		adapter = new NewsViewPagerAdapter(getActivity().getSupportFragmentManager(), fragArray);
		viewPager.setAdapter(adapter);
	}

}
